package com.financial.service.platbalancepay.mq;

import com.aliyun.openservices.ons.api.Producer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @anthor wenguoqiang
 * @date: 2019/06/10 9:24
 * @company 够样
 * @des
 **/
@Component
public class BalancePayResult {

    public static final Logger LOGGER = LoggerFactory.getLogger(BalancePayResult.class);


    @Autowired
    private Producer producer;


  /*  public boolean dealSynResult(Map<String, Object> params) {

        try {
            Map<String, Object> result = ysReportService.registryStore(params);
            Message message = new Message(BalancePayMQConfig.STORE_TOPIC, BalancePayMQConfig.YSREQUERTREPORTRESULT, JSONUtils.objectToJson(result).getBytes());
            LOGGER.error("报备信息"+new String(message.getBody()));
            producer.send(message);
        } catch (Exception e) {
            Message message = new Message(BalancePayMQConfig.YS_TOPIC, BalancePayMQConfig.YSREQUERTREPORTRESULTQUERY, JSONUtils.objectToJson(params).getBytes());
            // 设置延迟时间 15s
            message.setStartDeliverTime(System.currentTimeMillis() + 15000);
            LOGGER.error("再次报备"+new String(message.getBody()));
            producer.send(message);
            e.printStackTrace();
        }

        return true;
    }

    public boolean dealQueryResult(Map<String, Object> params) {

        Map<String, Object> queryResult = ysService.getYsState(params);
        String code = queryResult.get("code").toString();
        YsReportQueryDO ysReportQuery = new YsReportQueryDO();
        if ("10000".equals(code)) {
            //平台商唯一标识
            ysReportQuery.setMerchantNo(params.get("mer_outside_custid").toString());
            ysReportQuery.setIsSuccess("1");
            ysReportQuery.setCustid(queryResult.get("custid").toString());
            ysReportQuery.setCustname(queryResult.get("custname").toString());
            ysReportQuery.setCustStatue(queryResult.get("cust_status").toString());
            ysReportQuery.setUsercode(queryResult.get("usercode").toString());
            ysReportQuery.setUserStatus(queryResult.get("user_status").toString());
            ysReportQuery.setIsNeedContract(queryResult.get("is_need_contract").toString());
            ysReportQuery.setGmtCreate(new Date());
            ysReportQuery.setGmtModified(new Date());
            ysReportQuery.setIsDelete("1");
            ysReportQuery.setNote(queryResult.get("note").toString());
            ysReportQueryService.save(ysReportQuery);
            LOGGER.error("查询成功保存记录"+ysReportQuery.toString());
        }else {
            ysReportQuery.setMerchantNo(params.get("mer_outside_custid").toString());
            ysReportQuery.setNote(queryResult.get("sub_msg").toString());
            ysReportQuery.setIsDelete("1");
            ysReportQuery.setGmtCreate(new Date());
            ysReportQuery.setIsSuccess("2");
            ysReportQuery.setGmtModified(new Date());
            ysReportQueryService.save(ysReportQuery);
            LOGGER.error("查询失败返回信息条数"+ysReportQuery.toString());
        }
        Message message = new Message(BalancePayMQConfig.STORE_TOPIC, BalancePayMQConfig.YSREQUERTREPORTRESULTQUERY, JSONUtils.objectToJson(queryResult).getBytes());
        LOGGER.error("银盛报备查询回执信息"+new String(message.getBody()));
        producer.send(message);
        return true;
    }*/
}
